package com.sgb.goods.view.adapter.inquiry;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.RecyclerView;

import com.blankj.utilcode.util.ColorUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sgb.goods.BR;
import com.sgb.goods.R;
import com.sgb.goods.databinding.GoodsItemSupplierViewBinding;
import com.sgb.goods.entity.inquiry.SupplierEntity;
import com.sgb.goods.utils.base.adapter.BaseCommonAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import com.swgk.core.util.DisplayUtil;

import org.jetbrains.annotations.NotNull;

import java.util.List;

/**
 * 描述：询价发布
 * 供应商列表数据适配器
 *
 * @author qiangHeNoo
 * <p>
 * 时间：2021.12.13
 */
public class SupplierDataAdapter extends BaseQuickAdapter<SupplierEntity, BaseViewHolder> {

    public SupplierDataAdapter(Context context) {
        super(R.layout.goods_item_supplier_view);
    }

    @Override
    protected void convert(BaseViewHolder helper, SupplierEntity item) {
        GoodsItemSupplierViewBinding binding = DataBindingUtil.bind(helper.itemView);
        if (binding == null) {
            return;
        }
        binding.setVariable(BR.entity, item);
        binding.executePendingBindings();
        if (item.isModify()) {
            binding.goodsDeleteSupplier.setClickable(false);
        } else {
            binding.goodsDeleteSupplier.setClickable(true);
            helper.addOnClickListener(R.id.goods_delete_supplier);
        }
        showSupplierVipIcon(binding.goodsSupplierText, item);
    }

    private void showSupplierVipIcon(TextView tvCompany, SupplierEntity entity) {
        if (entity != null) {
            if ("1".equals(entity.getFlag())) {
                Drawable drawableLeft = mContext.getResources().getDrawable(R.mipmap.goods_icon_vip_supplier);
                tvCompany.setCompoundDrawablesWithIntrinsicBounds(drawableLeft, null,null , null);
                tvCompany.setCompoundDrawablePadding(DisplayUtil.convertDpToPixel(mContext, 5));
            } else {
                tvCompany.setCompoundDrawables(null, null, null, null);
            }
        }
    }

}
